package com.crk.shixiguanli.controller;

import com.crk.shixiguanli.entity.Job;
import com.crk.shixiguanli.entity.User;
import com.crk.shixiguanli.service.JobService;
import com.crk.shixiguanli.util.LayUiTableJson;
import com.crk.shixiguanli.util.Page;
import com.crk.shixiguanli.util.ResponseResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Description:
 *
 * @author:
 * Date: 2020-04-26
 * Time: 16:32
 */
@RestController
@RequestMapping("job")
public class JobController {
    @Autowired
    JobService jobService;

    /**
     * 列表页
     * @return
     */
    @RequestMapping("manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/job/jobList.html");
        return modelAndView;
    }

    @RequestMapping("show")
    public ModelAndView show(){
        User userinfo = (User) SecurityUtils.getSubject().getPrincipal();
        ModelAndView modelAndView = new ModelAndView("/workspace/job/jobShow.html");
        modelAndView.addObject("userType",userinfo.getUserType());
        return modelAndView;
    }


    /**
     * 详情页
     * @return
     */
    @GetMapping("detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/job/jobAdd.html");
        return modelAndView;
    }


    /**
     * 详情页
     * @return
     */
    @GetMapping("detailShow")
    public ModelAndView detailShow(){
        User userinfo = (User) SecurityUtils.getSubject().getPrincipal();
        ModelAndView modelAndView = new ModelAndView("/workspace/job/jobAddShow.html");
        modelAndView.addObject("userType",userinfo.getUserType());
        return modelAndView;
    }

    /**
     * 详情页
     * @return
     */
    @GetMapping("myJob")
    public ModelAndView myJob(){
        ModelAndView modelAndView = new ModelAndView("/workspace/job/myJob.html");
        return modelAndView;
    }



    /**
     * 分页查询
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("queryPage")
    public LayUiTableJson queryPage(@RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = jobService.queryPage(pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    /**
     * 查询所有
     * @return
     */
    @RequestMapping("queryAll")
    public ResponseResult queryAll(){
        return jobService.queryAll();
    }



    @RequestMapping("queryAllMyJob")
    public ResponseResult queryAllMyJob(){
        return jobService.queryAllMyJob();
    }

    /**
     * 查询单个
     * @return
     */
    @RequestMapping("getMyJob")
    public ResponseResult getMyJob(){
        return jobService.getMyJob();
    }


    /**
     * 查询单个
     * @param id
     * @return
     */
    @RequestMapping("getOneShow")
    public ResponseResult getOneShow(@RequestParam("id") Integer id){
        return jobService.getOneShow(id);
    }


    /**
     * 查询单个
     * @param id
     * @return
     */
    @RequestMapping("getOne")
    public ResponseResult getOne(@RequestParam("id") Integer id){
        return jobService.getOne(id);
    }


    /**
     * 加入岗位
     * @param id
     * @return
     */
    @RequestMapping("joinJob")
    public ResponseResult joinJob(@RequestParam("id") Integer id){
        return jobService.joinJob(id);
    }

    /**
     * 保存数据
     * @param job
     * @return
     */
    @RequestMapping("save")
    public ResponseResult save(Job job){
        return jobService.save(job);
    }

    /**
     * 删除数据
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public ResponseResult delete(@RequestParam("id") Integer id){
        return jobService.delete(id);
    }

    /**
     * 查询单个
     * @param id
     * @return
     */
    @RequestMapping("changeStatus")
    public ResponseResult changeStatus(@RequestParam("id") Integer id,@RequestParam("status") int status){
        return jobService.changeStatus(id,status);
    }



}
